"""
数据存储层
"""
import os
import pickle
from conf import setting
def save_data(obj):
    #获取文件夹路径
    class_path = obj.__class__.__name__
    class_path = os.path.join(setting.DATA_PATH,class_path)
    #判断文件夹是否存在
    if not os.path.exists(class_path):
        os.makedirs(class_path)
    #获取文件路径
    obj_path = obj.name
    obj_path = os.path.join(class_path,obj_path)
    #保存数据
    with open(obj_path,"wb") as f:
        pickle.dump(obj,f)

def select_data(cls,name):
    #拼接文件路径
    obj_path = os.path.join(setting.DATA_PATH,cls.__name__,name)
    # print("进入查询入口")
    # print(obj_path)
    if os.path.exists(obj_path):
        # print("有这个文件")
        with open(obj_path,"rb") as f:
            obj = pickle.load(f)
            # print(f"数据{obj}")
            return obj
    return None
        